<?php
namespace Admin\Controller;
use Admin\Model\TagModel;
use Admin\Model\ProjectModel;
use Admin\Model\FileModel;

/**
 * 标签控制器
 * 
 * @author xiaoyutab<xiaoyutab@qq.com>
 * @version v1.0.0
 * @copyright (c) 2017, xiaoyutab
 * @adtime 2018-06-10 12:31:41
 */
class TagController extends BashController{
    /**
     * 创建标签链接信息
     */
    public function create_linkAction(){
        $tag = new TagModel();
        $tar_id = $tag->get_link()->create_info(array(
            'file_id' => I('get.tid'),
            'target_id' => I('get.lid'),
            'target_name' => $tag->get_table_id(I('get.name'))
        ));
//        if($tar_id){
            $name = $tag->get_info(I('get.tid'));
            return $this->success($name['name'],$tar_id);
//        }
//        return $this->error('系统错误');
    }
    /**
     * 创建标签链接信息
     */
    public function create_link_projectAction(){
        $tag = new TagModel();
        $project = new ProjectModel();
        $tar_id = $tag->get_link()->create_info(array(
            'file_id' => I('get.tid'),
            'target_id' => I('get.lid'),
            'target_name' => $tag->get_table_id(I('get.name'))
        ));
//        if($tar_id){
            $name = $project->get_info(I('get.lid'));
            return $this->success($name['name'],$tar_id);
//        }
//        return $this->error('系统错误');
    }
    
    /**
     * 设置标签连接的删除状态
     * 
     * @return type
     */
    public function deleteAction(){
        $tag = new TagModel();
        $tag->set_delete_status(I('get.tid'),I('get.status',97,'intval'));
//        if($tag->set_delete_status(I('get.tid'),I('get.status',97,'intval'))){
        return $this->success('删除成功');
//        }
//        return $this->error('系统错误');
    }
    
    /**
     * 获取标签链接的详细信息
     * 需要链接ID编号
     */
    public function get_tag_infoAction(){
        $id = I('get.link_id');
        $tag = new TagModel();
        $file = new FileModel();
        // 链接详情
        $tag_info = $tag->get_link()->get_info($id);
        // 标签详情
        $tag_info['tag_info'] = $tag->get_info($tag_info['file_id']);
        // 标签所关联的图片详情
        $tag_info['file_list'] = $file->get_img_all('tag', $tag_info['file_id']);
        // 链接所关联的图片编号
        $tag_info['link_file'] = $file->get_img_all('tag_link', $id);
        echo json_encode($tag_info);exit;
    }
}